import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    flag: 0,
    role_id: 0,
    funcList: [],
    pageList: [],
    isShowProject: sessionStorage.getItem("isShowProject") ? true : false, // 是否显示项目菜单
    isMunicipalBureau: sessionStorage.getItem("isMunicipalBureau") ? true : false, // 区分市局与区县 true 市局
    curSection: sessionStorage.getItem("curSection") || "",
  },
  mutations: {
    setFlag(state, flag) {
      state.flag = flag;
    },
    setRoleId(state, role_id) {
      state.role_id = role_id;
    },
    setFuncList(state, fun_permission_list) {
      state.funcList = fun_permission_list;
    },
    setPageList(state, page_permission_list) {
      state.pageList = page_permission_list;
    },
    setShowProject(state, data) {
      state.isShowProject = data;
      sessionStorage.setItem("isShowProject", data);
    },
    setMunicipalBureau(state, data) {
      state.isMunicipalBureau = data;
      sessionStorage.setItem("isMunicipalBureau", data);
    },
    setCurSection(state, data) {
      state.curSection = data;
      sessionStorage.setItem("isMunicipalBureau", data);
    },
  },
  actions: {},
  modules: {},
  plugins: [createPersistedState()],
});
